﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Database.Model.Roles>>" %>
<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="System.Threading" %>
<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdRoles";
                                        settings.KeyFieldName = "IdRole";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "RolesPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.RoleNameRu;
                                            column.FieldName = "RoleNameRu";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.RoleNameEn;
                                            column.FieldName = "RoleNameEn";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.IsActive;
                                            column.FieldName = "IsActive";
                                            column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdProfineRegion";
                                            column.Caption = Resourses.profineRegions;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new profineRegionsCollection();

                                                comboBoxProperties.DataSource = col.profineRegionsList;
                                                comboBoxProperties.TextField = "profineRegionLocalizedName";
                                                comboBoxProperties.ValueField = "IdProfineRegion";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdRolesType";
                                            column.Caption = Resourses.RolesTypes;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new RolesTypesCollection();
                                                comboBoxProperties.DataSource = col.RolesTypesList;
                                                comboBoxProperties.TextField = "RolesTypeLocalizedName";
                                                comboBoxProperties.ValueField = "IdRolesType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "RolesPartialUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "RolesPartialAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "RolesPartialDelete" };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                    })
       .Bind(Model).GetHtml();
%>
